<?php
namespace Plu\Library\Models\Platform\Media;

use Phalcon\Mvc\Model,
    Phalcon\Db\Column;

class QCloudNewFileUpload extends Model {
    public $Id;

    public $LiveId;

    public $FileId;

    public $Cover;

    public $FileUrl;

    public $SourceType;

    public $SourceContext;

    public $TranscodeTaskId;

    public $ProcedureTaskId;

    public $Author;

    public $StreamId;

    public $Duration;

    public $Size;

    public $Width;

    public $Height;

    public $Bitrate;

    public $Container;

    public $Creater;

    public $CreateTime;

    public $Updater;

    public $UpdateTime;

    public $QCloudNewFileUploadcol;

    public function initialize() {
        $this->setReadConnectionService('db.platform.slave');
        $this->setWriteConnectionService('db.platform'); 
        $this->hasOne(
            'LiveId',
            'ReplayMedia',
            'LiveId'
        );
    }

    public function getSource() {
        return 'QCloudNewFileUpload';
    }

    static public function getVideos() {
        $result = self::find();
        return $result;
    }

    static public function getItem($LiveId) {
        $where = [
            'LiveId = :LiveId:',
            'bind'  =>  [
                'LiveId'    =>  $LiveId,
            ],
        ];
        $result = self::find($where);

        if ($result) {
            $result = $result->toArray();
        } else {
            $result = false;
        }
        return $result;

    }

    static public function getNewItem($LiveId) {
        $where = [
            'LiveId = :LiveId: ORDER BY CreateTime DESC',
            'bind'  =>  [
                'LiveId'    =>  $LiveId,
            ],
        ];
        $result = self::findFirst($where);

        return $result;
    }
}
?>
